<template>
  <div>
    <div class="panel-heading">客户信息</div>
    <FormPanel :list="orderInformationList" :cols="4" :isSubmitBtn="false" />
    <div class="panel-heading">制定对策</div>
    <FormPanel ref="formPanel1" :list="examineInformationList" :cols="4" :isSubmitBtn="false" @formChange="formChangeHandle1"></FormPanel>
    <div class="panel-heading">服务总监审批</div>
    <FormPanel ref="formPanel2" :list="directorApprovalList" :cols="4" :isSubmitBtn="false" @formChange="formChangeHandle2"></FormPanel>
    <div class="panel-heading">方案执行记录</div>
    <FormPanel ref="formPanel3" :list="executionRecordList" :cols="4" :isSubmitBtn="false" @formChange="formChangeHandle3"></FormPanel>
    <div class="panel-heading">厂家意见建议</div>
    <FormPanel :list="manufactorOpinionList" :cols="1" :isSubmitBtn="false" />
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button type="primary">完成</el-button>
      <el-button type="primary">审核</el-button>
      <el-button type="primary">取消审核</el-button>
      <el-button type="primary" @click="save">保存</el-button>
      <el-button type="primary" @click="closeFilter">取消</el-button>
    </div>
  </div>
</template>
<script>
import moment from 'moment';
import { getUserId, getUser } from '@/assets/js/auth';
import { save } from '@/api/repair/management/analysis';
export default {
  name: 'examineVerify',
  props: ['list'],
  data() {
    this.BaseTable = null;
    return {
      saveData: {},
      orderInformationList: this.createOrderTable(),
      tableList: [],
      examineInformationList: this.auditInformationTable(),
      directorApprovalList: this.directorApprovalTable(),
      executionRecordList: this.executionRecordTable(),
      manufactorOpinionList: this.manufactorOpinionTable()
    };
  },
  mounted() {
    this.queryExaminaList(); // 提交结算弹窗数据传入
    this.formChangeHandle1();
    this.formChangeHandle2();
    this.formChangeHandle3();
  },
  methods: {
    createOrderTable() {
      return [
        {
          type: 'INPUT',
          label: '问题序号',
          fieldName: 'PROBLEM_NO',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '统计月',
          fieldName: 'MONTH',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车系',
          fieldName: 'SERIES_NAME',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '底盘号',
          fieldName: 'VIN',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '进场日期',
          fieldName: 'PROBLEM_DESC',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'OWNER_CODE',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'ownerName',
          selfCols: 2,
          disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: 'FIR问题描述',
          fieldName: 'PROBLEM_DESC',
          initialValue: '',
          selfCols: 4,
          disabled: true
        },
        {
          type: 'INPUT',
          label: '送修人',
          fieldName: 'DELIVERER',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '送修电话',
          fieldName: 'DELIVERER_MOBILE',
          disabled: true
        }
      ];
    },
    auditInformationTable() {
      return [
        {
          type: 'SELECT',
          label: '产生问题的控制节点',
          fieldName: 'NODE_CODE',
          labelWidth: '120px',
          selfCols: 2,
          itemList: [
            { text: '常备库存优化', value: 'BJ01' },
            { text: '急件订货', value: 'BJ02' },
            { text: '入库&库位管理', value: 'BJ03' },
            { text: '出库', value: 'BJ04' },
            { text: '预约准备', value: 'BJ05' },
            { text: '合理派工', value: 'JD01' }
          ]
        },
        {
          type: 'INPUT',
          label: '分析问题真因',
          fieldName: 'PROBLEM_REASON',
          labelWidth: '120px',
          selfCols: 4
        },
        {
          type: 'INPUT',
          label: '制定对策',
          fieldName: 'PROBLEM_SOLUTION',
          labelWidth: '120px',
          selfCols: 4
        }
      ];
    },
    directorApprovalTable() {
      return [
        {
          type: 'INPUT',
          label: '问题解决方案',
          fieldName: 'PROBLEM_PLAN',
          labelWidth: '100px',
          selfCols: 4
        }
      ];
    },
    executionRecordTable() {
      return [
        {
          type: 'INPUT',
          label: '工作执行情况',
          fieldName: 'PERFORMANCE',
          labelWidth: '100px',
          selfCols: 4
        },
        {
          type: 'INPUT',
          label: '方案效果评估',
          fieldName: 'EFFECTIVE_EVALUATION',
          labelWidth: '100px',
          selfCols: 4
        }
      ];
    },
    manufactorOpinionTable() {
      return [
        {
          type: 'INPUT',
          label: '厂家意见建议',
          fieldName: 'TDS_OPINION',
          labelWidth: '100px',
          disabled: true
        }
      ];
    },
    async formChangeHandle1(val) {
      Object.assign(this.saveData, val);
    },
    async formChangeHandle2(val) {
      Object.assign(this.saveData, val);
    },
    async formChangeHandle3(val) {
      Object.assign(this.saveData, val);
    },
    tablechangeFun(val) {
      this.Pdi = val;
    },
    // 主页面数据传入
    async queryExaminaList() {
      const dataList = this.list;
      const formList = [...this.orderInformationList, ...this.examineInformationList, ...this.directorApprovalList, ...this.executionRecordList];
      formList.forEach(x => {
        x.initialValue = dataList[x.fieldName];
      });
      this.manufactorOpinionList.find(item => item.fieldName === 'TDS_OPINION').initialValue = dataList['TDS_OPINION'];
    },
    // 保存
    async save() {
      const dataList = this.list;
      this.$refs.formPanel1.SUBMIT_FORM();
      this.$refs.formPanel2.SUBMIT_FORM();
      this.$refs.formPanel3.SUBMIT_FORM();
      this.saveData['PROBLEM_NO'] = dataList['PROBLEM_NO'];
      console.log('saveData', this.saveData);
      let res = await save(this.saveData);
      if (res.resultCode == 200 && res.data == '1') {
        this.$notify.success({ title: '提示信息', message: '保存成功!' });
        this.closeFilter();
      }
    },

    // 字符串转驼峰
    camelcase(str) {
      let arr = str.split('_');
      let upper = arr.map((val, index) => {
        let lowStr = val.toLowerCase();
        if (index) {
          lowStr = lowStr.charAt(0).toLocaleUpperCase() + lowStr.slice(1);
        }
        return lowStr;
      });
      return upper.join('');
    },

    // 取消
    closeFilter() {
      this.$emit('closeFilter');
    }
  }
};
</script>
<style lang="less" scoped>
.panel-heading {
  color: #34495e;
  background-color: #f5f5f5;
  border-color: #ddd;
  padding: 10px 15px;
  margin-bottom: 10px;
}
.model-footer {
  padding: 15px;
  margin-top: 0px;
  text-align: right;
  height: 40px;
  line-height: 40px;
}
.sp {
  display: block !important;
}
/deep/ .radioBox .el-radio__label {
  display: initial;
}
</style>
